<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE>
<html>
   <head>
   	   <meta charset="utf8">
   	   <meta name="viewport" content="width=device-width, initial-scale=1">
       <link rel="stylesheet" type="text/css" href="/aquaticproduct/Public/css/bootstrap.min.css">
       <link rel="stylesheet" type="text/css" href="/aquaticproduct/Public/css/sticky-footer-navbar.css">
       <script type="application/javascript" src="/aquaticproduct/Public/js/jquery-1.11.1.min.js"></script>
       <script type="application/javascript" src="/aquaticproduct/Public/js/bootstrap.min.js"></script>
   	   <title>水产品质量溯源系统</title>

   </head>
<body>
    <!-- Fixed navbar -->
    <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
      <div class="container">
	        <div class="navbar-header">
	          <button type="button" class="navbar-toggle" data-toggle="collapse" 
		         data-target="#navbar">
		         <span class="sr-only">切换导航</span>
		         <span class="icon-bar"></span>
		         <span class="icon-bar"></span>
		         <span class="icon-bar"></span>
		      </button>
	          <a class="navbar-brand" href="<?php echo U('Home/Index/iindex');?>">水产品质量溯源系统</a>
	        </div>
	        <div id="navbar" class="collapse navbar-collapse" >
	          <ul class="nav navbar-nav">
	            <li class="dropdown">
	            	<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">个人中心<span class="caret"></span></a>
	            	   <ul class="dropdown-menu">
		                <li><a href="<?php echo U('Home/User/showMe',array('role'=> '3'));?>">个人信息</a></li>
		                <li ><a href="<?php echo U('Home/Index/logout');?>" style="color:red">退出</a></li>	
		              </ul>
	            </li> 

	            <li class="dropdown">
	              <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">功能列表 <span class="caret"></span></a>
	              <ul class="dropdown-menu">
	                <li><a href="<?php echo U('Home/Safe/index');?>">养殖基本信息</a></li>
					<li><a href="<?php echo U('Home/Safe/cultivation', array('name'=>'stocking'));?>">养殖管理</a></li>
	                <li><a href="#">出塘管理</a></li>
	                <li><a href="#">质量追溯</a></li>	                
	              </ul>
	            </li>
	              <li><a href="<?php echo U('Home/Test/test');?>">扫描自动录入信息</a></li>
	          </ul>
	        </div><!--/.nav-collapse -->
      </div>
    </nav>
    
    <div class="container">
    	<div class="row">
    		<div class="col-sm-9">
    		  
   <div class="panel panel-info">
	   <div class="panel-heading">
	      <h3 class="panel-title">
	         用药记录
	      </h3>
	   </div>
	   <div class="panel-body">
	       <button class="btn btn-lg btn-primary"  data-toggle="modal" data-target="#addMedicationModal">添加</button><br><br>
	   	<table class="table table-bordered table-striped col-sm-12" >
		     <thead>
		        <tr>
		           <th>药品</th>
		           <th>使用剂量</th>
	           <?php if($pool_data['pool_model'] == '网箱'): ?><th>网箱</th><?php endif; ?>
		           <th>用药时间</th>
		           <th>用药理由</th>
		           <th>用药方式</th>
		           <th>注意事项</th>
		           <th>操作</th>
		        </tr>
		     </thead>
		     <tbody>
		     	<?php if(is_array($medication)): $i = 0; $__LIST__ = $medication;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$medication): $mod = ($i % 2 );++$i;?><tr>
			           <td><?php echo ($medication["medication_medicine_id"]); ?></td>
			           <td><?php echo ($medication["medication_amount"]); ?></td>
			         <?php if($pool_data['pool_model'] == '网箱'): ?><td><?php echo ($medication["medication_cage_id"]); ?></td><?php endif; ?>  
			           <td><?php echo ($medication["medication_time"]); ?></td>
			           <td><?php echo ($medication["medication_reason"]); ?></td>
			           <td><?php echo ($medication["medication_pattern"]); ?></td>
			           <td><?php echo ($medication["medication_precautions"]); ?></td>
		               <td><button class="btn btn-danger" data-toggle="modal" data-target="#modifyMedicationModal" value="<?php echo ($medication["medication_id"]); ?>" onclick="medicationChange(this)">修改</button></td>
			        </tr><?php endforeach; endif; else: echo "" ;endif; ?> 
			  
		     </tbody>
 		 </table>
	   </div>
	     <div class="panel-footer">
	     	<ul class="pagination">
			 <?php echo ($page); ?>
		    </ul>
	     </div>
	</div>
	<!-- medicationModal -->
<div class="modal fade" id="addMedicationModal" tabindex="-1" role="dialog" 
   aria-labelledby="myModalLabel" aria-hidden="true">
		   <div class="modal-dialog">
		      <div class="modal-content">
		         <div class="modal-header">
		            <button type="button" class="close" 
		               data-dismiss="modal" aria-hidden="true">
		                  &times;
		            </button>
		            <h4 class="modal-title" id="myModalLabel">
		               新用药信息
		            </h4>
		         </div>
		         <div class="modal-body">
		            <form action="<?php echo U('Home/Safe/adds', array('name' => 'medication'));?>" id="addMedication_form" role="form" method="post">
		            	<div class="form-group">
		            		<label for="">药品</label>
		            		<select class="form-control" name="medication_medicine_id" >
		            			<option value="0">请选择药品</option>
		            			<?php if(is_array($medicine)): $i = 0; $__LIST__ = $medicine;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$m): $mod = ($i % 2 );++$i;?><option value="<?php echo ($m["medicine_id"]); ?>"><?php echo ($m["medicine_name"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
		            		</select>
		            	</div>
		            	<div class="form-group">
		            		<label for="">所用剂量</label>
		            		<input type="text" class="form-control" value="" name="medication_amount" >
		            	</div>
                        <?php if($pool_data['pool_model'] == '网箱'): ?><div class="form-group">
			            		<label for="">网箱</label>
				            		<select class="form-control" name="medication_cage_id" >
				            			<option value="0">请选择网箱</option>
				            			<?php if(is_array($cage)): $i = 0; $__LIST__ = $cage;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$ca): $mod = ($i % 2 );++$i;?><option value="<?php echo ($ca["cage_id"]); ?>"><?php echo ($ca["cage_rowname"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
				            		</select>
			            	    </else>
			            	</div><?php endif; ?>
		            	<div class="form-group">
		            		<label for="">用药时间</label>
		            		<input type="text" class="form-control" value="" name="medication_time" >
		            	</div>
		            	<div class="form-group">
		            		<label for="">用药理由</label>
		            		<input type="text" class="form-control" value="" name="medication_reason" >
		            	</div>
		            	<div class="form-group">
		            		<label for="">用药方式</label>
		            		<input type="text" class="form-control" value="" name="medication_pattern" >
		            	</div>
		            	<div class="form-group">
		            		<label for="">注意事项</label>
		            		<input type="text" class="form-control" value="" name="medication_precautions" >
		            	</div>
		            	
		            	<label class="control-label" for="input01" name="time">当前时间: <?php echo ($time); ?> </label>
		            </form>
		         </div>
		         <div class="modal-footer">
		            <button type="button" class="btn btn-default" 
		               data-dismiss="modal">关闭
		            </button>
		            <button type="button"  id="addMedicationBtn" class="btn btn-primary">
		               提交
		            </button>
		         </div>
		      </div><!-- /.modal-content -->
		</div><!-- /.modal -->

</div>

<!-- ModifyfryModal -->
<div class="modal fade" id="modifyMedicationModal" tabindex="-1" role="dialog" 
   aria-labelledby="myModalLabel" aria-hidden="true">
		   <div class="modal-dialog">
		      <div class="modal-content">
		         <div class="modal-header">
		            <button type="button" class="close" 
		               data-dismiss="modal" aria-hidden="true">
		                  &times;
		            </button>
		            <h4 class="modal-title" id="myModalLabel">
		               修改用药信息
		            </h4>
		         </div>
		         <div class="modal-body">
		            <form action="<?php echo U('Home/Safe/modify', array('name' => 'Medication'));?>" id="modifyMedication_form" role="form" method="post">
		            	<div class="form-group">
		            		<label for="">药品</label>
		            		<select class="form-control" name="medication_medicine_id" id="medication_medicine_id">
		            			<option value="0">请选择药品</option>
		            			<?php if(is_array($medicine)): $i = 0; $__LIST__ = $medicine;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$m): $mod = ($i % 2 );++$i;?><option value="<?php echo ($m["medicine_id"]); ?>"><?php echo ($m["medicine_name"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
		            		</select>
		            	</div>
		            	<div class="form-group">
		            		<label for="">所用剂量</label>
		            		<input type="text" class="form-control" value="" name="medication_amount" id="medication_amount">
		            	</div>
                        <?php if($pool_data['pool_model'] == '网箱'): ?><div class="form-group">
			            		<label for="">网箱</label>
				            		<select class="form-control" name="medication_cage_id" id="medication_cage_id">
				            			<option value="0">请选择网箱</option>
				            			<?php if(is_array($cage)): $i = 0; $__LIST__ = $cage;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$ca): $mod = ($i % 2 );++$i;?><option value="<?php echo ($ca["cage_id"]); ?>"><?php echo ($ca["cage_rowname"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
				            		</select>
			            	    </else>
			            	</div><?php endif; ?>
		            	<div class="form-group">
		            		<label for="">用药时间</label>
		            		<input type="text" class="form-control" value="" name="medication_time" id="medication_time">
		            	</div>
		            	<div class="form-group">
		            		<label for="">用药理由</label>
		            		<input type="text" class="form-control" value="" name="medication_reason" id="medication_reason">
		            	</div>
		            	<div class="form-group">
		            		<label for="">用药方式</label>
		            		<input type="text" class="form-control" value="" name="medication_pattern" id="medication_pattern">
		            	</div>
		            	<div class="form-group">
		            		<label for="">注意事项</label>
		            		<input type="text" class="form-control" value="" name="medication_precautions" id="medication_precautions">
		            	</div>
		            	<label class="control-label" for="input01" name="time">当前时间: <?php echo ($time); ?> </label>
		                <div class="form-group hidden">
		            		<input type="text" class="form-control" value="" name="medication_id" id="medication_id" >
		            	</div>
		            </form>
		         </div>
		         <div class="modal-footer">
		            <button type="button" class="btn btn-default" 
		               data-dismiss="modal">关闭
		            </button>
		            <button type="button"  id="modifyMedicationBtn" class="btn btn-primary">
		               提交修改
		            </button>
		         </div>
		      </div><!-- /.modal-content -->
		</div><!-- /.modal -->
</div>

    		</div>

	       <div class="col-sm-3">
	       	   
  <h1><strong>养殖管理</strong></h1>
   	  <ul class="nav nav-pills nav-stacked">
   	  	<li><a href="<?php echo U('Home/Safe/cultivation', array('name' => 'stocking'));?>">放养管理</a></li>
   	  	<li><a href="<?php echo U('Home/Safe/cultivation', array('name' => 'feeding'));?>">投饲管理</a></li>
   	  	<li><a href="<?php echo U('Home/Safe/cultivation', array('name' => 'patrol'));?>">巡塘管理</a></li>
   	  	<li class="active"><a href="<?php echo U('Home/Safe/cultivation', array('name' => 'medication'));?>">用药管理</a></li>
   	  	<li><a href="<?php echo U('Home/Safe/cultivation', array('name' => 'indicator'));?>">养殖指标管理</a></li>
   	  	<li><a href="#">病害管理</a></li>
   	  	<li><a href="#">自动获取数据采集指标</a></li>
   	  </ul>

	       </div>
	    </div> <!-- row -->
    	
   </div> <!-- container -->

   
    <footer class="footer">
      <div class="container">
        <p class="text-muted"><center>Copyright by 华南农业大学</center></p>
      </div>
    </footer>
    
  </body>
</html>
 
	<script>
	function medicationChange(obj) { 
	       
			var val = $(obj).attr('value');
	        var url = "<?php echo U('Home/Safe/getChoose/name/Medication/val/"+val+"');?>";
	        $.get(url, function(data, status){

	        	$('#medication_id').val(data['medication_id']);
	        	// $('#medication_fry_id').val(data['medication_fry_id']);
	        	// $('#medication_cage_id').val(data['medication_cage_id']);
	        	$('#medication_amount').val(data['medication_amount']);
	        	$('#medication_time').val(data['medication_time']);
	        	$('#medication_reason').val(data['medication_reason']);
	        	$('#medication_pattern').val(data['medication_pattern']);
	        	$('#medication_precautions').val(data['medication_precautions']);
	        });
	}
	$(document).ready(function(){

	      $('#addMedicationBtn').click(function(){
	             var action = $('#addMedication_form').attr('action');
	             var Formattr = $('#addMedication_form').serialize();
	             $.post(action, Formattr, function(data,status) {
	                 if(status == "success") {
	                    alert( "添加成功！");
	                 }else{
	                 	alert("添加失败！");
	                 }
	                 setTimeout("window.location.href=\"<?php echo U('Home/Safe/cultivation', array('name' => 'medication'));?>\"",200);
	             });
	        });
	      $('#modifyMedicationBtn').click(function(){

	        	 var action= $('#modifyMedication_form').attr('action');
	        	 var Formattr=$('#modifyMedication_form').serialize();
		         console.log(Formattr);
	             $.post(action, Formattr,function(data,status) {
	                 
	                 if(status == "success") {
	                    alert( "修改成功！");
	                 }else{
	                 	alert("修改失败！");
	                 }
	                 setTimeout("window.location.href=\"<?php echo U('Home/Safe/cultivation', array('name' => 'medication'));?>\"",200);
	             });
	        });
	});
	</script>